<template>
  <div class="home">
    <img alt="Vue logo" src="../assets/logo.png" />
    <HelloWorld msg="Welcome to Your Vue.js App" />
    <HelloWorld msg="Welcome to Your Vue.js App" />
    <HelloWorld msg="Welcome to Your Vue.js App" />
    <HelloWorld msg="Welcome to Your Vue.js App" />
    <HelloWorld msg="Welcome to Your Vue.js App" />
  </div>
</template>

<script>
// @ is an alias to /src
import HelloWorld from "@/components/HelloWorld.vue";

export default {
  data() {
    return {
      scrollY: 0,
    };
  },
  name: "HomeView",
  components: {
    HelloWorld,
  },
  // deactivated() {
  //   console.log(document.documentElement.scrollTop);
  // },
  beforeRouteLeave(to, from, next) {
    // ...
    console.log(document.documentElement.scrollTop);
    //打印当前滚动条的距离
    this.scrollY = document.documentElement.scrollTop;
    next();
  },
  //在路由离开之前保存滚动条的距离
  activated() {
    document.documentElement.scrollTop = this.scrollY;
  },
  //在进入页面把刚才保存的距离再次赋值给scrolltop
};
</script>
